package com.qf.boot220301.controller;

import com.baomidou.kaptcha.exception.KaptchaIncorrectException;
import com.baomidou.kaptcha.exception.KaptchaNotFoundException;
import com.baomidou.kaptcha.exception.KaptchaTimeoutException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    KaptchaController kaptchaController;
    @RequestMapping("login")
    public String login(String username,String password,String captchar){

     try {
         kaptchaController.validDefaultTime(captchar);
     }catch (Exception e){
         if (e instanceof KaptchaIncorrectException) {
             return "验证码不正确";
         } else if (e instanceof KaptchaNotFoundException) {
             return "验证码未找到";
         } else if (e instanceof KaptchaTimeoutException) {
             return "验证码过期";
         } else {
             return "验证码渲染失败";
         }

     }


        return "验证码正确";

    }
}
